package com.ty.enums;

import cn.hutool.core.collection.CollUtil;
import lombok.Getter;
import lombok.Setter;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public enum FileType {
    IMAGES(1,"images/", CollUtil.newArrayList("jpg","png","gif","bmp","jpeg")),
    VIDEO(2,"video/",CollUtil.newArrayList("mp4","avi","wmv")),
    DOC(3,"doc/",CollUtil.newArrayList("doc","docx","xls","xlsx","ppt","txt","pptx","pdf","md","epub","mobi","azw3","chm","rtf","wps","cvs","djvu","pdf","xps","tex","html","htm","wml"));

    @Setter @Getter
    private int code;
    @Setter @Getter
    private String folder;
    @Setter @Getter
    private List<String> exts;

    FileType (int code,String folder,List<String> exts){
        this.code =code;
        this.folder =folder;
        this.exts = exts;
    }

    public static FileType getByCode(int code){
        FileType[] values = FileType.values();
        Optional<FileType> first = Arrays.stream(values).filter(item -> item.getCode() == code).findFirst();

        return first.orElse(null);
    }
}
